import { ChatOllama } from "@langchain/ollama";
import { PromptTemplate } from "@langchain/core/prompts";
import { StringOutputParser } from "@langchain/core/output_parsers";
import { TOPICS, MODEL, TEMPERATURE } from "./config.js";

// 创建模块
const prompt = PromptTemplate.fromTemplate("请使用中文解释：{topic}");
const model = new ChatOllama({ model: MODEL, temperature: TEMPERATURE });
const parser = new StringOutputParser();

const chain = prompt.pipe(model).pipe(parser);

// 多条输入
const inputs = [];
TOPICS.forEach((item) => {
  inputs.push({
    topic: item,
  });
});
// inputs --> [{topic: "闭包"}, {topic: "原型链"}, ....]

// 批量执行
const results = await chain.batch(inputs);

// 输出结果
results.forEach((res, i) => {
  console.log(`第 ${i + 1} 条结果：`, res);
});
